package demo;

/**
 * 生成存储54张扑克牌，然后打乱。
 * <p>
 * Version: 1.0
 * Author: 瓶子
 */
public class FightLandlords {
    public static void main( String[] args ) {
        String[] pokers = generatePoker();
        printPoker(pokers);
        System.out.println("");
        shuffle(pokers);
        printPoker(pokers);
    }

    // 生成54张不同花色的牌。
    public static String[] generatePoker() {
        // 创建数组存储54张牌
        String[] pokers = new String[54];
        // 定义数组存储点数
        String[] poker = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
        String[] colors = { "♠", "♥", "♣", "♦" };

        // 先遍历花色，再遍历点数
        for ( int i = 0; i < colors.length; i++ ) {
            for ( int j = 0; j < poker.length; j++ ) {
                // 拼接花色和点数，放到总数组中
                pokers[i * 13 + j] = colors[i] + poker[j];
            }
        }
        // 大小王
        pokers[52] = "小王";
        pokers[53] = "大王";

        return pokers;
    }

    // 列出数组内容
    public static void printPoker( String[] pokers ) {
        for ( int i = 0; i < pokers.length; i++ ) {
            System.out.print(pokers[i] + " ");
        }
    }

    // 洗牌
    public static void shuffle( String[] pokers ) {
        for ( int i = 0; i < pokers.length; i++ ) {
            int index = ( int ) (Math.random() * pokers.length);
            // 数据交换
            String temp = pokers[i];
            pokers[i] = pokers[index];
            pokers[index] = temp;
        }
    }
}
